using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Graphics;
using WPCoco.Helpers;
using WPCoco.Tilesets.Codecs;

namespace WPCoco.Tilesets
{
    public partial class Tileset
    {
        static Tileset()
        {
             types = ReflectionHelper.TypesForInterface(typeof(ITilesetReader));
        }

        static Type[] types;

        public static Tileset LoadFrom(XDocument document, Texture2D texture)
        {
            ITilesetReader reader = null;
            foreach (var t in types)
            {
                reader = Activator.CreateInstance(t) as ITilesetReader;
                if (reader.CanRead(document)) break;
            }
            if (reader == null) return null;
            return reader.Read(document, texture);
        }
    }
}
